<template>
	<view >
		<product :list="list" @togoodsinfo="toDetail"></product>
		<kong v-if="list.length==0"></kong>
	</view>
</template>

<script>
import kong from '../../components/kong.vue'
import product from '../../components/goods.vue'
export default {
	components:{
		kong,product
	},
	data() {
		return {
			world: '',
			page: 1,
			list: [],
			loading: false,
			isEnd: false
		}
	},
	onLoad(options) {
		this.world = options.world
		uni.setNavigationBarTitle({ title: options.world })
		this.getList()
	},
	methods: {
		async getList() {
			if (this.loading || this.isEnd) {
				return
			}
			this.loading = true
			try {
				let res = await this.$http({
					url: 'api/wechat/searchGoods',
					data: {
						page_index: this.page,
						page_size: 10,
						keyword: this.world
					}
				})
				this.list = [...this.list, ...res.data]
				this.page++
				if (res.data.length < 10) {
					this.isEnd = true
				}
			} finally {
				this.loading = false
			}
		},
		toDetail(item){
			uni.navigateTo({ url: '/pageshop/goodsinfo/goodsinfo?id='+item.id })
		}
	}
}
</script>

<style>
	page{
		background-color: #FFF;
	}
</style>
